package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.android.volley.toolbox.ImageLoader;
import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.activity.MainActivity;
import com.lanou.sfu.songforu.datas.RecommendPlayDatas;
import com.lanou.sfu.songforu.singleton.VolleySingleton;
//import com.squareup.picasso.Picasso;
import java.util.List;

/**
 * Created by quyan on 15/10/21.
 */
public class RecommendAdapter extends PagerAdapter {
    private List<RecommendPlayDatas.PicEntity>datases;
    private Context mContext;
    private ImageLoader imageLoader;
    private MainActivity activity;

    public RecommendAdapter(Context mContext, List<RecommendPlayDatas.PicEntity> playDatases) {
        this.mContext = mContext;
        this.datases = playDatases;
        activity = (MainActivity) mContext;
        Log.i("lanou2","" + datases);
        imageLoader = VolleySingleton.getInstance(mContext).getImageLoader();
    }
    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
            ImageView imageView = new ImageView(mContext);

            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    activity.skepFragemnt(position % datases.size(), datases);

                }
            });
            String image = datases.get(position % datases.size()).getRandpic();
            Log.i("lanou1",image + " ");
            ImageLoader.ImageListener listener = ImageLoader.getImageListener
                    (imageView, R.mipmap.default_ticker,R.mipmap.default_ticker);
            imageLoader.get(image,listener);
           // Picasso.with(mContext).load(image).into(imageView);
            container.addView(imageView);//加入布局
            return imageView;
        }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
